package com.ilovepostcard.view;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.provider.MediaStore;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import com.ilovepostcard.DiscoverActivity;
import com.ilovepostcard.EditImageActivity;
import com.ilovepostcard.LaunchCreateActivity;
import com.ilovepostcard.MainActivity;
import com.ilovepostcard.MyActivity;
import com.ilovepostcard.R;
import com.ilovepostcard.utils.Constants;
import com.ilovepostcard.utils.ImageUtil;
import com.ilovepostcard.utils.NetWorkUtil;
import com.ilovepostcard.utils.Utils;
import com.ilovepostcard.view.PostcardMenuItem.OnMenuClickListener;
import com.mobclick.android.MobclickAgent;


public class PostcardMainMenu extends RelativeLayout {

	  View view ;
      View submenu;
      PostcardMenuItem menuCreate;
      PostcardMenuItem menuCreateCamera;
      PostcardMenuItem menuCreateGallery;
      PostcardMenuItem menuDiscover;
      PostcardMenuItem menuMy;
    public PostcardMainMenu(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        inflate();
    }

    public PostcardMainMenu(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate();
    }

    public PostcardMainMenu(Context context) {
        super(context);
        inflate();
    }
    
    public void showButtonText(boolean show)
    {
    	menuCreate.showText(show);
    	menuCreateCamera.showText(show);
    	menuCreateGallery.showText(show);
    	menuDiscover.showText(show);
    	menuMy.showText(show);
    }


    private void inflate() {
        view = inflate(getContext(), R.layout.postcard_main_menu, this);
        submenu = view.findViewById(R.id.main_sub_menu);
        menuCreate = (PostcardMenuItem) view.findViewById(R.id.menu_create);
        menuCreateCamera = (PostcardMenuItem) view.findViewById(R.id.menu_create_camera);
        menuCreateGallery = (PostcardMenuItem) view.findViewById(R.id.menu_create_gallery);
        menuDiscover = (PostcardMenuItem) view.findViewById(R.id.menu_discover);
        menuMy = (PostcardMenuItem) view.findViewById(R.id.menu_my);
        
        menuCreate.setOnMenuClickListener(new OnMenuClickListener() {
            
            @Override
            public void onClickMenu() {
                submenu.setVisibility(menuCreate.isSelected() ? View.VISIBLE : View.INVISIBLE);  
                MobclickAgent.onEvent(PostcardMainMenu.this.getContext(), Constants.COUNT_CREAT);
            }
        });
        
        menuCreateCamera.setOnMenuClickListener(new OnMenuClickListener() {
            
            @Override
            public void onClickMenu() {
            	MobclickAgent.onEvent(PostcardMainMenu.this.getContext(), Constants.COUNT_CREAT_CAMERA);
            	Intent intent = new Intent(getContext(), LaunchCreateActivity.class);
                intent.putExtra(LaunchCreateActivity.LAUNCH_TYPE_KEY, LaunchCreateActivity.LAUNCH_TYPE_CAMERA);
                getContext().startActivity(intent);
            }
        });
        
        menuCreateGallery.setOnMenuClickListener(new OnMenuClickListener() {
            
            @Override
            public void onClickMenu() {
            	MobclickAgent.onEvent(PostcardMainMenu.this.getContext(), Constants.COUNT_CREAT_ALBUM);
                Intent intent = new Intent(getContext(), LaunchCreateActivity.class);
                intent.putExtra(LaunchCreateActivity.LAUNCH_TYPE_KEY, LaunchCreateActivity.LAUNCH_TYPE_GALLERY);
                getContext().startActivity(intent);
            }
        });
        
        menuDiscover.setOnMenuClickListener(new OnMenuClickListener() {
            
            @Override
            public void onClickMenu() {
            	MobclickAgent.onEvent(PostcardMainMenu.this.getContext(), Constants.COUNT_DISCOVER);
                if (NetWorkUtil.haveInternet(getContext())) {
                    Intent intent = new Intent(getContext(), DiscoverActivity.class);
                    getContext().startActivity(intent);
                } else {
                    Utils.showNetworkSettingDialog(getContext());
                }
            }
        });
        
        menuMy.setOnMenuClickListener(new OnMenuClickListener() {
            
            @Override
            public void onClickMenu() {
            	MobclickAgent.onEvent(PostcardMainMenu.this.getContext(), Constants.COUNT_MY);
                if (NetWorkUtil.haveInternet(getContext())) {
                    Intent intent = new Intent(getContext(), MyActivity.class);
                    getContext().startActivity(intent);
                } else {
                    Utils.showNetworkSettingDialog(getContext());
                }
            }
        });
    }
}
